feat(ai-openai): add gpt-image-2 to image model meta#625
Conversation
📝 WalkthroughWalkthroughAdds OpenAI ChangesGPT-Image-2 Model Support
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install failed: lockfile failed supply-chain policy check. Run Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🚀 Changeset Version Preview2 package(s) bumped directly, 0 bumped as dependents. 🟨 Minor bumps
🟩 Patch bumps
|
|
View your CI Pipeline Execution ↗ for commit c32b43d
☁️ Nx Cloud last updated this comment at |
|
View your CI Pipeline Execution ↗ for commit c32b43d
☁️ Nx Cloud last updated this comment at |
@tanstack/ai
@tanstack/ai-anthropic
@tanstack/ai-client
@tanstack/ai-code-mode
@tanstack/ai-code-mode-skills
@tanstack/ai-devtools-core
@tanstack/ai-elevenlabs
@tanstack/ai-event-client
@tanstack/ai-fal
@tanstack/ai-gemini
@tanstack/ai-grok
@tanstack/ai-groq
@tanstack/ai-isolate-cloudflare
@tanstack/ai-isolate-node
@tanstack/ai-isolate-quickjs
@tanstack/ai-ollama
@tanstack/ai-openai
@tanstack/ai-openrouter
@tanstack/ai-preact
@tanstack/ai-react
@tanstack/ai-react-ui
@tanstack/ai-solid
@tanstack/ai-solid-ui
@tanstack/ai-svelte
@tanstack/ai-utils
@tanstack/ai-vue
@tanstack/ai-vue-ui
@tanstack/openai-base
@tanstack/preact-ai-devtools
@tanstack/react-ai-devtools
@tanstack/solid-ai-devtools
commit: |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/media/image-generation.md`:
- Line 93: The documentation's OpenAI model overview bullet list is missing
`gpt-image-2` causing inconsistency with the tables; update the overview bullet
list in image-generation.md to include `gpt-image-2` (matching the table row
that lists `gpt-image-2` and its sizes `1024x1024`, `1536x1024`, `1024x1536`,
`auto`) so the intro bullets and the detailed table are consistent.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 13a5ffb1-ba94-451b-8c3b-1f5b2567f5df
📒 Files selected for processing (6)
.changeset/openai-gpt-image-2.mddocs/media/image-generation.mdpackages/typescript/ai-openai/src/adapters/image.tspackages/typescript/ai-openai/src/image/image-provider-options.tspackages/typescript/ai-openai/src/model-meta.tspackages/typescript/ai/skills/ai-core/media-generation/SKILL.md
Adds `gpt-image-2` to OPENAI_IMAGE_MODELS so it can be used through openaiImage adapters. Reuses the gpt-image-1 provider-options/size shape (quality, background, output_format, output_compression, moderation, partial_images; sizes 1024x1024 / 1536x1024 / 1024x1536 / auto) and extends size + prompt-length validators. Also updates the media-generation skill and image-generation doc page to list the new model.
c32b43d to
65784fa
Compare
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/typescript/ai-openai/src/image/image-provider-options.ts (1)
184-195: 🛠️ Refactor suggestion | 🟠 Major | 🏗️ Heavy liftUse Zod schemas as the single source of truth for image-model constraints.
packages/typescript/ai-openai/src/image/image-provider-options.tshard-codes runtime rules invalidateImageSize(e.g.,validSizes),validateBackground(supportedModels), andvalidatePrompt(model-specific prompt limits), whileOpenAIImageModelSizeByNameseparately defines/derives model/size constraints—yet this file contains no Zod schemas/imports. Move these model/size/background/prompt rules into Zod and infer the exported types/maps from that schema (to keep runtime and type-level constraints in sync).🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/typescript/ai-openai/src/image/image-provider-options.ts` around lines 184 - 195, The file currently duplicates model/size/background/prompt rules across runtime validators and a separate OpenAIImageModelSizeByName type; replace those hard-coded runtime lists by defining Zod schemas (e.g., ImageModelSchema, ImageModelConfigSchema) that declare each model's supported sizes, backgrounds, and prompt constraints, import z from Zod, infer TypeScript types via z.infer and derive the OpenAIImageModelSizeByName map from the schema, then update validateImageSize, validateBackground, and validatePrompt to read constraints from the Zod-backed config (or validate against the Zod schemas directly) instead of using hard-coded validSizes/supportedModels/prompt limits so runtime and type-level rules stay in sync.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@packages/typescript/ai-openai/src/image/image-provider-options.ts`:
- Around line 184-195: The file currently duplicates
model/size/background/prompt rules across runtime validators and a separate
OpenAIImageModelSizeByName type; replace those hard-coded runtime lists by
defining Zod schemas (e.g., ImageModelSchema, ImageModelConfigSchema) that
declare each model's supported sizes, backgrounds, and prompt constraints,
import z from Zod, infer TypeScript types via z.infer and derive the
OpenAIImageModelSizeByName map from the schema, then update validateImageSize,
validateBackground, and validatePrompt to read constraints from the Zod-backed
config (or validate against the Zod schemas directly) instead of using
hard-coded validSizes/supportedModels/prompt limits so runtime and type-level
rules stay in sync.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: f365fb03-3b0a-40a2-a6ba-bcddaca7fc49
📒 Files selected for processing (8)
.changeset/openai-gpt-image-2.md.changeset/openrouter-web-fetch-tool-capability.mddocs/media/image-generation.mdpackages/typescript/ai-openai/src/adapters/image.tspackages/typescript/ai-openai/src/image/image-provider-options.tspackages/typescript/ai-openai/src/model-meta.tspackages/typescript/ai-openrouter/src/model-meta.tspackages/typescript/ai/skills/ai-core/media-generation/SKILL.md
✅ Files skipped from review due to trivial changes (5)
- packages/typescript/ai-openai/src/adapters/image.ts
- .changeset/openrouter-web-fetch-tool-capability.md
- packages/typescript/ai/skills/ai-core/media-generation/SKILL.md
- docs/media/image-generation.md
- .changeset/openai-gpt-image-2.md
Summary
gpt-image-2toOPENAI_IMAGE_MODELSso it can be selected through theopenaiImageadapter (generate({ adapter: openaiImage(...), model: 'gpt-image-2', ... }))quality,background,output_format,output_compression,moderation,partial_images) and size set (1024x1024,1536x1024,1024x1536,auto); the OpenAI docs for gpt-image-2 expose the samev1/images/generations+v1/images/editsendpoints with the same request parametersvalidateImageSize,validateBackground, andvalidatePrompt(32 000-char limit) to recognize the new modelpackages/typescript/ai/skills/ai-core/media-generation/SKILL.mdanddocs/media/image-generation.mdto listgpt-image-2@tanstack/ai-openaiPricing source: OpenAI gpt-image-2 model page. Token-based pricing recorded in
ModelMetais text-input $5 / cached $1.25 / image-output $30 per 1M tokens; the schema does not have a separate field for the $8 image-input-token rate (same limitation as the existinggpt-image-1entry).Test plan
pnpm --filter @tanstack/ai-openai test:typespnpm --filter @tanstack/ai-openai test:eslint(no new warnings/errors)gpt-image-1; the adapter call path is unchanged forgpt-image-2, so no new fixture was added. Add one if reviewers want gpt-image-2 exercised in CI.Summary by CodeRabbit
New Features
Documentation
Bug Fixes